﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SmartSpace.Core;

namespace SmartSpace.Workflow.DriveEvents
{
    /// <summary>
    /// 发送给自己
    /// </summary>
    public class SendToSelfDriveEvent : IWorkflowDriveEvent
    {
        public WorkflowDriveRecord Drive(
            WorkflowInstance instance, 
            WorkflowMetadata workflow, 
            ActivityMetadata activity, 
            EventMetadata @event, 
            WorkflowDriveRecord currentRecord, 
            Guid dataId, User sender, 
            IEnumerable<Guid> receivers)
        {
            // 关闭上一步
            if (currentRecord != null)
            {
                currentRecord.IsActivated = false;
            }

            WorkflowDriveRecord driveRecord = new WorkflowDriveRecord();
            driveRecord.Id = Guid.NewGuid();
            driveRecord.InstanceId = instance.Id;
            driveRecord.WorkflowId = instance.WorkflowId;
            driveRecord.ActivityId = @event.ToActivityId;
            driveRecord.EventId = @event.Id;
            driveRecord.SenderId = sender.Id;
            driveRecord.ReceiverId = sender.Id;
            driveRecord.ReceiverType = WfReceiverType.User;
            driveRecord.DrivedDate = DateTime.Now;
            driveRecord.RecordId = dataId;
            driveRecord.IsActivated = true;
           
            return driveRecord;
        }
    }
}
